package com.zmm.study.order.controller;

import com.zmm.common.base.model.Result;
import com.zmm.common.base.model.ResultCode;
import com.zmm.common.enums.OrderStatusEnum;
import com.zmm.study.order.model.MoNiOrder;
import com.zmm.study.order.service.OrderService;
import com.zmm.util.time.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author 900045
 * @description:
 * @name CreateOrderController
 * @date By 2021-10-19 19:53:04
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class CreateOrderController {


	@Resource
	private OrderService orderService;

	@GetMapping("/test/create/order")
	public Result createOrderTest(Integer count){
		// 1.假设订单下单成功
		MoNiOrder moNiOrder = new MoNiOrder();
		String orderNo = UUID.randomUUID().toString();
		moNiOrder.setOrderNo(orderNo);
		moNiOrder.setStatus(OrderStatusEnum.CREATE_NEW.getCode());
		Long nowTime = DateUtil.getNowTime();
		log.info("第{} 次创建订单,此时时间是:{},订单号为:{}",count,DateUtil.getDateTime(nowTime),orderNo);

		orderService.submitOrder(moNiOrder);

		// 2.给MQ 发送消息 下单成功 配置文件中的手动确认 spring.rabbitmq.publisher-confirms=true
		//rabbitTemplate.convertAndSend("order-event-exchange","order.create.order",moNiOrder)
		return Result.ok(ResultCode.SUCCESS);
	}
}
